$(function(){
	
	//发送验证码功能
	$("#getCode").click(function(){
		var phoneNo = $("#phoneNo").val();
		var status = "0";   // 0注册  1登录

		var data = {
						"params": {
			       			 phoneNo: phoneNo,
			       			 status: status
			   			 }
			   		}
		var jsonData = JSON.stringify(data);
		$.ajax({
			url: urlLink + "/bMaMarketCustInfo/phoneCaptcha",
			type: "POST",
			contentType: "application/json; charset=utf-8",
			data:jsonData,
			success:function(data){
				if (data.code == "0000") {
					alert("发送验证码成功");

				}else{
					alert(data.msg);
				}
			},
			error: function(data){
				console.log(data);
				alert("服务器繁忙");
			}
		})

	});

	//注册功能
	$("#register").click(function(){
		var phoneNo = $("#phoneNo").val();
		var password = $("#password").val();
		var qrCode = $("#qrCode").val();
		var channel = localStorage.getItem("channel");
		var num = localStorage.getItem("num");
		var code = $("#code").val();
		var sourceSign = "H5";   //1 表示贷盟主H5  2表示落地页
		var appMarket = "贷盟主H5";
		if (phoneNo == null || phoneNo.length == 0) {
			alert("手机号不能为空");
			 return false; 
		}
		var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/; 
		if(!myreg.test(phoneNo)) 
		{ 
		    alert('请输入有效的手机号码！'); 
		    return false; 
		}
		if (code == null || code.length == 0) {
			alert("验证码不能为空");
			 return false; 
		}
		if (password == null || password.length == 0) {
			alert("密码不能为空");
			 return false; 
		}
		var reg = /^[0-9A-Za-z]{6,20}$/;   //6-20位数字字母组合
		if(!reg.test(password)) 
		{ 
		    alert('请输入有效的密码！'); 
		    return false; 
		}
		
		var data = {
						"params": {
							"phoneNo": phoneNo,
			       			"code": code,
			       			"password": password,
			       			"qrCode": qrCode,
			       			"channelSource": channel,
			       			"appMarket": appMarket,
			       			"num": num,
			       			"sourceSign": sourceSign
			   			 }
			   		}
		var jsonData = JSON.stringify(data);
		console.log(jsonData);
		$.ajax({
			url: urlLink + "/bMaMarketCustInfo/reg",
			type: "POST",
			contentType: "application/json; charset=utf-8",
			data:jsonData,
			success:function(data){
				if (data.code == "0000") {
					alert("注册成功,请登录");
					window.location.href = "login.html";
				}
				else if (data.code == "8956") {
					alert(data.msg);
				}
				else if (data.code == "8891") {
					alert(data.msg);
				}else{
					alert(data.msg);
				}
			},
			error: function(data){
				console.log(data);
				alert("服务器繁忙");
			}
		})
	});
})